package com.moioo.exam;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for
 * TExamPaperSet entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.moioo.exam.TExamPaperSet
 * @author MyEclipse Persistence Tools
 */

public class TExamPaperSetDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(TExamPaperSetDAO.class);
	// property constants
	public static final String ITYPE = "itype";
	public static final String IKEY = "ikey";
	public static final String STR = "str";
	public static final String STR1 = "str1";
	public static final String STR2 = "str2";
	public static final String INT1 = "int1";
	public static final String INT2 = "int2";

	public void save(TExamPaperSet transientInstance) {
		log.debug("saving TExamPaperSet instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TExamPaperSet persistentInstance) {
		log.debug("deleting TExamPaperSet instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TExamPaperSet findById(java.lang.Integer id) {
		log.debug("getting TExamPaperSet instance with id: " + id);
		try {
			TExamPaperSet instance = (TExamPaperSet) getSession().get(
					"com.moioo.exam.TExamPaperSet", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(TExamPaperSet instance) {
		log.debug("finding TExamPaperSet instance by example");
		try {
			List results = getSession().createCriteria(
					"com.moioo.exam.TExamPaperSet").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TExamPaperSet instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from TExamPaperSet as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByItype(Object itype) {
		return findByProperty(ITYPE, itype);
	}

	public List findByIkey(Object ikey) {
		return findByProperty(IKEY, ikey);
	}

	public List findByStr(Object str) {
		return findByProperty(STR, str);
	}

	public List findByStr1(Object str1) {
		return findByProperty(STR1, str1);
	}

	public List findByStr2(Object str2) {
		return findByProperty(STR2, str2);
	}

	public List findByInt1(Object int1) {
		return findByProperty(INT1, int1);
	}

	public List findByInt2(Object int2) {
		return findByProperty(INT2, int2);
	}

	public List findAll() {
		log.debug("finding all TExamPaperSet instances");
		try {
			String queryString = "from TExamPaperSet";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TExamPaperSet merge(TExamPaperSet detachedInstance) {
		log.debug("merging TExamPaperSet instance");
		try {
			TExamPaperSet result = (TExamPaperSet) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TExamPaperSet instance) {
		log.debug("attaching dirty TExamPaperSet instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TExamPaperSet instance) {
		log.debug("attaching clean TExamPaperSet instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}